<template>
  <div style="min-width: 809px">
    <div v-if="$route.path == '/companyList'">
      <div class="vs-search-box">
        <el-form ref="form" :inline="true" :model="paging" label-width="120px">
          <el-form-item label="公司名称">
            <el-input type="text" v-model="paging.name"></el-input>
          </el-form-item>
          <el-form-item label="" class="vs-right-btns">
            <el-button @click="reset">重置</el-button>
            <el-button @click="handleCurrentChange(1)" type="primary"
              >查询</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <div class="vs-table-box">
        <div class="operation-box clear-float">
          <el-button style="margin-left: auto" type="primary" @click="setRow(1)"
            >新增</el-button
          >
        </div>
        <el-table
          v-loading="loading"
          :data="tableData"
          header-row-class-name="has-gutter-table"
          style="width: 100%"
        >
          <!-- <el-table-column prop="username" label="门店" min-width="150">
          </el-table-column> -->
          <el-table-column prop="name" label="公司名称"> </el-table-column>
          <el-table-column prop="tax_rate" label="税率（%）" > </el-table-column>
          <el-table-column prop="identification" label="纳税人识别号">
          </el-table-column>
          <el-table-column prop="address" label="地址"> </el-table-column>
          <el-table-column prop="phone" label="电话"> </el-table-column>
          <el-table-column prop="bank_name" label="开户行"> </el-table-column>
          <el-table-column prop="bank_account" label="开户行账号">
          </el-table-column>
          <!-- <el-table-column
            prop="bank_name"
            label="开票人名称"
            min-width="150"
          >
          </el-table-column> -->
          <el-table-column label="操作" fixed="right">
            <template slot-scope="scope">
              <span @click="setRow(2, scope.row)" class="tab-table-text"
                >编辑</span
              >
              <span @click="setRow(3, scope.row)" class="tab-table-text"
                >查看</span
              >
              <span @click="setRow(4, scope.row)" class="tab-red-text"
                >删除</span
              >
            </template>
          </el-table-column>
        </el-table>
        <div class="vs-paging-box">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="paging.page"
            :page-size="paging.limit"
            layout="sizes,prev, pager, next, jumper"
            :total="paging.total"
          >
          </el-pagination>
        </div>
      </div>
    </div>
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [],
      loading: false,
      paging: {
        name: "",
        page: 1,
        total: 0,
        limit: 10,
      },
      tableData: [],
    };
  },
  created() {
    this.homegetStore();
    this.repairGetList();
  },
  methods: {
    async setRow(type, row) {
      if (type == 1) {
        this.utils.goUrl("/editCompany?type=" + type);
      } else if (type == 4) {
        this.$msgbox({
          title: "提示",
          message: "您确定要删除此公司吗?",
          type: "warning",
          showCancelButton: true,
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          beforeClose: async (action, instance, done) => {
            if (action === "confirm") {
              instance.confirmButtonLoading = true;
              instance.confirmButtonText = "删除中...";
              let { code, data } = await this.$Http.delCompany({ id: row.id });
              if (code) {
                this.$message.success("删除成功!");
                this.handleCurrentChange(1);
              }
              done();
              instance.confirmButtonLoading = false;
            } else {
              done();
            }
          },
        })
          .then((action) => {})
          .catch(() => {});
      } else {
        this.utils.goUrl(`/editCompany?type=${type}&id=${row.id}`);
      }
    },
    // 获取全部门店
    async homegetStore() {
      let { code, data } = await this.$Http.homegetStore();
      if (code) {
        this.list = data;
      }
    },
    async repairGetList() {
      this.loading = true;
      let { code, data } = await this.$Http.getCompany(this.paging);
      this.loading = false;
      if (code) {
        this.tableData = data.data;
        this.paging.limit = data.per_page;
        this.paging.total = data.total;
      }
    },
    handleSizeChange(val) {
      this.paging.limit = val;
      this.repairGetList();
    },
    handleCurrentChange(val) {
      this.paging.page = val;
      this.repairGetList();
    },
    reset() {
      //重置
      this.paging = this.$options.data().paging;
      this.handleCurrentChange(1);
    },
  },
};
</script>

<style lang="scss" scoped>
.image-thumbnail {
  width: 130px;
  height: 130px;
}
</style>